package com.jhws.sys.role.service;

import java.util.List;

import com.jhws.core.db.BaseDao;
import com.jhws.sys.menu.bo.TblMenuDimBo;
import com.jhws.sys.role.bo.TblRolemenuDimBo;

import javax.annotation.Resource;

public class TblRolemenuDimServiceSpringImpl implements ITblRolemenuDimService {
	@Resource
	private BaseDao BaseDao;

	public void deleteTblRolemenuDimByMenuCode(String menuCode) {
		BaseDao.deleteByColumns("TblRolemenuDimBo","menuCode",menuCode);
	}

	public void deleteTblRolemenuDimByRoleCode(String roleCode) throws Exception{
        BaseDao.deleteByColumns("TblRolemenuDimBo","roleCode",roleCode);
	}

	public TblRolemenuDimBo save(TblRolemenuDimBo bo) {
		return (TblRolemenuDimBo)BaseDao.save(bo);
	}

	public List<TblRolemenuDimBo> findTblRolemenuDimByWhere(String whereClause) throws Exception {
		return BaseDao.findList("from TblRolemenuDimBo "+whereClause);
	}

	public List<TblMenuDimBo> getMenuByRole(String roleCode) {
		return BaseDao.findList("from TblRolemenuDimBo where roleCode = '"+roleCode+"'");
	}

	public List<String> getPermsByRole(String roleCode){
		return BaseDao.findList("select new java.lang.String(m.permission) " +
                "from TblRolemenuDimBo as rm,TblMenuDimBo as m " +
                "where  rm.roleCode = '"+roleCode+"' and rm.menuCode = m.menuCode and m.permission IS NOT NULL");
	}

}
